<link rel="stylesheet" href="css/aliceui.min.css"/>
<link rel="stylesheet" href="css/resetui.css"/>
<link rel="stylesheet" href="css/reg.css"/>
<style type="text/css">
#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}
	#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}
.mctit_nbg{background-image:none;}
.tab_wrap{display:none;}
.tab_show{display:block;}
#create_new_lnk{display: none;}
.message{border: 1px solid #0088cc;}#t {
	width: 324px;
	margin: 5px auto;
	padding:0px;
	border-top: #ccc 1px solid;
	border-left: #ccc 1px solid;
	display:table;
}
#t li {float: left;width: 80px;height: 50px;list-style-type: none;border-right:#ccc 1px solid;
	border-bottom: #ccc 1px solid;text-align: center;line-height: 50px;
}
fieldset{width:807px;height:520px; border: 1px solid #E1E1E1;}
legend{margin-left:15px;font-weight:bold; font-size:14px;color:#121212;}
a { text-decoration:none; color:#000;}
li { list-style:none;}
.center { margin:0 auto; width:800px;}
.title { width:780px; height:30px;  margin-top:-25px; line-height:30px; text-align:right; padding-right:15px;}
.nav { width:800px;  margin-top:15px; overflow:hidden;}
.nav ul li { width:800px; float:left; height:130px;}
.nav ul li ul li{ width:153px; float:left; height:100px; border:1px solid #E1E1E1; margin-left:5px;margin:6px 0 0 6px;}
.nav ul li ul li.first { margin-left:0;}
.red{color:red;}
.wodeziti{margin-left: 13px;
font-weight: bold;
font-size: 12px;
color: ##990F62;}
td {text-align: center;} 
/*width="130" height="68" align="left" valign="middle"*/
</style>
<script type="text/javascript">document.title="加入联盟";</script>
<!--主体-->
<div class="r_content" id="register">
    <h3 class="mc_title">
        <span class="mctit_1"><span class="mctit_2">加入联盟</span></span>
    </h3>
	  <a href="javascript:void(0);" class="ckall">全选</a> 
       <a href="javascript:void(0);" class="reck">反选</a> 
    <form id="reg_form" class="reg_form" style="margin:0;">
        <?=$data['csrf_token'];?>
        <input type="hidden" name="action" value="RelationshipCreate"/>
        <input type="hidden" name="actionType" value="CreateDistor"/>
        <input type="hidden" name="dtype" value="1"/>
    
	<table id="selected_distor">
    <thead>
    <tr>
        <th class="first">分销商名称</th>
        <th>公司类型</th>
        <th>联系人</th>
        
    </tr>
    </thead>
    <tbody id="selected_distor_list" >
	<tr>
		<td class="first" style="text-align:left">[100001]先行旅游</td>
		<td style="text-align:left">电商/团购网</td>
		<td style="text-align:left">先行旅游[18050790190]</td>
	</tr>
	</tbody>
	<tbody class="uc">
	<tr class="underling">
		<td class="first_a" style="text-align:left"><input type="checkbox" class="tids" >[200002]下级一</td>
		<td style="text-align:left">电商/团购网</td>
		<td style="text-align:left">先行旅游[18050790190]</td>
	</tr>
	<tr class="underling">
		<td class="first_a" style="text-align:left"><input type="checkbox"  class="tids">[200003]下级二</td>
		<td style="text-align:left">电商/团购网</td>
		<td style="text-align:left">先行旅游[18050790190]</td>
	</tr>
	<tr class="underling">
		<td class="first_a" style="text-align:left"><input type="checkbox" class="tids" >[200004]下级三</td>
		<td style="text-align:left">电商/团购网</td>
		<td style="text-align:left">先行旅游[18050790190]</td>
	</tr>
	</tbody>
</table>
<div class="w_join">
	<span class="w_join_t">希望加入的联盟</span>
	<hr>
	<input type="checkbox" class="al">先行分销联盟
	<input type="checkbox" >去哪儿分销联盟
</div>
<input type="submit" class="l_save" value="保存">
</form>
</div>
</div>
</div>
<!--<script type="text/javascript" src="js/jquery.getareas.js"></script>-->
<!--    <script type="text/javascript" src="js/easydialog.min.js"></script>-->
<script type="text/javascript" src="js/fun.inc.js"></script>
<script type="text/javascript" src="js/prod_pub.js"></script>
<script type="text/javascript" src="js/reg_new.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
	$("a#create_new_lnk").on('click', function(){
	if($(this).hasClass('opened')) {
		$("#create_new_one").hide();
		$("table#com_type").show();
		$("#selected_distor").show();
		$(this).removeClass('opened').text('创建新分销商');
	} else {
		$("#create_new_one").show();
		$("table#com_type").hide();
		$("#selected_distor").hide();
		$(this).addClass('opened').text('选择已有分销商');
		if(verify.isTel($("input[name=s_val]").val())){
			$("input[name=company]").val('');
			$("input[name=mobile]").val($("input[name=s_val]").val());
		}else{
			$("input[name=mobile]").val('');
			$("input[name=company]").val($("input[name=s_val]").val());
		}
	}

});
$(document).ready(function(){
	$("#selected_distor").on('click', '.selected_distor_add', function(){
		var did = $(this).attr('data-id'),
		param = {
			action: 'AddRelationShip',
			distor: did,
			token : check.getToken()
		},	elem = $(this);
		
		$.post(url,param,function(json_res){
			if(json_res.status=='ok') {
				elem.parent('td').html('已添加|<a target="_blank" href="priceset.html?did='+did+'">价格配置</a>');
			} else {
				alert(json_res.msg);
			}
			},'json');
		});
	});

});
$("input[name=s_val]").on('keyup', function(){
	if(verify.isTel($(this).val())){
		getMember($(this),true);
		return false;
	}else if(verify.is_chinese($(this).val())){
		tab3.find(".error").html('分销商必须是中文开头').hide();
		getMember($(this),false);
	}else{
		tab3 = $(this).parents("tr").find('td.tab3');
		tab3.find(".error").html('分销商必须是中文开头').show();
		tab3.show();
	}
});


$("input[name=s_val]").on('focus', function(){
	if(!verify.is_chinese($(this).val())){
		tab3 = $(this).parents("tr").find('td.tab3');
		tab3.find(".error").html('分销商必须是中文开头').show();
		tab3.show();
	}

	$("#create_new_one").hide();
	$("table#com_type").show();
	$("#selected_distor").show();
	$("a#create_new_lnk").removeClass('opened').text('创建新分销商');
});

	
// 获取搜索分销商列表
function getMember(obj,isTel){
	var val = obj.val(),listTxt = '', bEqual=false;
	if(val=='') return false;
	if(isTel){// 手机号搜索
		$.getJSON('call/jh_mem.php',{action:'chkAndGet',mobile:val})
		.done(function(salers){
			
		   if((typeof salers.ajaxMobile!='undefined' && salers.ajaxMobile!=null) || (typeof salers.status!='undefined' && salers.status!=1) ){
				listTxt=getParTpl(salers);
			}else{
				$("#create_new_lnk").show();
			}				
			$("#selected_show_list").html("");
			$("#selected_show_list").append(listTxt);
		});
	}else{ // 分销商名称模糊搜索
		$.getJSON('call/jh_mem.php',{action:'fuzzyGetDname',dname:val})
		.done(function(salers){
			for(var k in salers) {
				if(salers[k].dname==val) bEqual=true;
				listTxt+=getParTpl(salers[k]);
			}
			$("#selected_show_list").html("");
			$("#selected_show_list").append(listTxt);
			if(bEqual==false) $("#create_new_lnk").show();
		});

	}
	
	
};


$(document).ready(function(){
    $(".ckall").click(function(){ // 全选
        $(".tids").attr("checked",true).parent().parent().find(':text').attr('disabled',false);
    });
    $(".reck").click(function(){// 反选
        $(".tids").each(function(index,element){
            $(this).attr("checked",!this.checked).parent().parent().find(':text').attr('disabled',!this.checked);
        });
    });
    $(".add").click(function(){
        var cs = 0;
        $(".pri").each(function(index,element){
            if(!element.disabled){
                cs = Number($(this).val());
                if(cs==0) cs = Number($(".gpri").eq(index).html());
                cs = cs + 1;
                $(this).val(cs);
            }
            
        });
    });
    });
</script>